package com.wyy.test

import org.junit.platform.commons.util.ReflectionUtils
import org.mockito.Mockito
import org.spockframework.util.ReflectionUtil
import spock.lang.Specification
import spock.util.concurrent.PollingConditions

import java.lang.reflect.Method
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors

/**
 * @Date: 2025/4/22
 * @Author: wyy  
 */
class SpockTest extends Specification {

    def "test_async_call_mocked_method"() {
        given:
        Map map = Mock(HashMap)
        map.get('a') >> 123
        def threadPool = Executors.newFixedThreadPool(3)
        when:
        def b
        threadPool.submit {
            b = map.get('a')
        }
        then:
        new PollingConditions(timeout: 2)
                .eventually {
                    assert b == 1233
                }
    }

    def test_override_method() {
        given:
        def m = Spy(new TestOverridePrivateMethod())

        when:
        m.pub()
        then:
        1*m.priv()
    }
}
